package com.zoweunion.mechanic.controller.base;


import com.github.pagehelper.PageInfo;
import com.zoweunion.mechanic.controller.BaseController;
import com.zoweunion.mechanic.entity.PartsDailyBean;
import com.zoweunion.mechanic.model.ResponseBean;
import com.zoweunion.mechanic.service.base.PartsManagerService;
import com.zoweunion.mechanic.util.ExcelUtils;
import com.zoweunion.mechanic.util.MyException;
import com.zoweunion.mechanic.util.constants.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/PartsManager")
public class PartsManagerController extends BaseController {

    @Autowired
    private PartsManagerService partsManagerService;
    /**
     * 配件数量日统计
     *
     * */
    @PostMapping("/partsDailyStatistics")
    public ResponseBean partsDailyStatistics (@RequestBody Map<String, Object> reqmap) throws MyException {
        logBefore(logger, "配件数据日统计");
        PageInfo datamap = partsManagerService.getPartsDailyStatistics(reqmap);
        logAfter(logger);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", datamap);
    }

    /**
     * 配件数量日统计
     *
     * */
    @GetMapping("/partsDailyExport")
    public void partsDailyExport (@RequestParam Map<String, Object> reqmap, HttpServletResponse response) throws Exception {
        logBefore(logger, "配件导出");
        List<PartsDailyBean> partsDailyExport = partsManagerService.partsDailyExport(reqmap);
        logAfter(logger);
        ExcelUtils.exportExcelToTarget(response, "配件统计信息", partsDailyExport, PartsDailyBean.class);
    }

    /**
     * 配件编号列表
     *
     * */
    @PostMapping("/partsCodeList")
    public ResponseBean partsCodeList (@RequestBody Map<String, Object> reqMap) throws Exception {
        logBefore(logger, "配件数据日统计");
        List<String> partsCode = partsManagerService.getPartsCode(reqMap);
        logAfter(logger);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", partsCode);
    }

    /**
     * test
     * 批量补录数据
     * */
    @PostMapping("/test2")
    public ResponseBean test2 () throws MyException {
        logBefore(logger, "test");
//        cgOrderService.countParts();
        partsManagerService.getDailyPartsTest();
        logAfter(logger);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", null);
    }
}
